import { ref } from 'vue'
import { getProductNameListApi } from '@/api/productBase/BaseInfo'

const useProduct = () => {
  const productNameList = ref([])
  const getProductNameList = (query) => {
    // if(query){
      productNameList.value = []
      getProductNameListApi().then(res => {
        setTimeout(() => {
          const product = res.data.resultList.filter(item => {
            return item.pdName.includes(query)
          })
          productNameList.value = product.map(product => {
            return {
              type: 'option',
              value: product.pdCode, 
              label: product.pdName, 
              createDate: product.createDate, 
              endDate: product.endDate 
            }
          })
        }, 200)
      })
    // }
  }

  return {
    productNameList,
    getProductNameList,
  }
}

export default useProduct